package
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	import http.HttpLoader;
	public class Example extends Sprite
	{
		public var i:int =48;
		public var arr:Array;
		public function Example()
		{
			if (stage){
				init();
			}
			else {
				addEventListener(Event.ADDED_TO_STAGE, init);
			}
			/*loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete);
			request = new URLRequest("App.swf");
			var loaderContext:LoaderContext = new LoaderContext();
			loaderContext.applicationDomain = ApplicationDomain.currentDomain;
			loader.load(request, loaderContext);*/
			
		}
		
		private function init(...args):void{
			HttpLoader.getInstance().httpJson("http://127.0.0.1/GetMagicList.json",callback);
		}
		public function callback(data:Object):void{
			 arr=data as Array;
			 loadImage();
			
		}
		private function loadImage(...args):void{
			
			var load:Loader=new Loader();
			load.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImage);
			
			var url:URLRequest=new URLRequest("http://ninjacdn.brokenbulbstudios.com/swf/relicshopgfx/"+i.toString()+".png");
			i++;
			trace(url.url);
			load.load(url);
		}
		
		
		
		private function swfComplete(e:Event):void
		{
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfComplete);
//			var dis:DisplayObject = loader.content;
//			var loaderInfo:LoaderInfo = dis.loaderInfo;
//			var applicationDomain:ApplicationDomain = loaderInfo.applicationDomain;
			var applicationDomain:ApplicationDomain = ApplicationDomain.currentDomain;
			/*try
			{*/
				//var map1:map=new map();
				var myClass:Class = applicationDomain.getDefinition("App") as Class;
				
				this.stage.addChild(new myClass());
				this.parent.removeChild(this);
			/*}
			catch (e:Error)
			{
				
			}*/
		}
		
		private var loader:Loader;
		private var request:URLRequest;
	}
}